package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentsMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

@Service
public class ReportServiceImpl implements ReportService {



    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentsMapper studentsMapper;

    /**
     * 员工职位人数统计
     * @return
     */
    public JobOption empJobData() {
        List<Map<String,Object>> list=empMapper.empJobData();

        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new JobOption(jobList,dataList);
    }

    /**
     * 员工性别人数统计
     *
     * @return
     */
    public List<Map<String, Object>> empGenderData() {
        List<Map<String,Object>> genderList=empMapper.empGenderData();
        return genderList;
    }

    /**
     * 学生学历人数统计
     * @return
     */
    public List<Map<String, Object>> studentDegreeData() {
        List<Map<String, Object>> degreeList = studentsMapper.studentDegreeData();
        return degreeList;
    }

    /**
     * 学生班级人数统计
     * @return
     */
    public ClazzOption studentCountData() {
        List<Map<String, Object>> list = studentsMapper.studentCountData();
        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("clazzList")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("dataList")).toList();
        return new ClazzOption(clazzList,dataList);
    }
}
